package com.example.noval.network.repository

import android.util.Log
import com.example.noval.db.mode.SearchResp
import com.example.noval.network.ServiceCreator
import com.example.noval.network.api.ApiResult
import com.example.noval.utils.ext.GSON
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import retrofit2.http.Path

/**
 * @Description
 * @Author zzl
 * @Date 2024/3/25
 */
class SearchRepository {


    suspend fun searchBook(page: Int, pageSize:Int, keyword:String): ApiResult<List<SearchResp>> = withContext(Dispatchers.IO){
        
        val map=HashMap<String,String>()
        map["keyword"]=keyword
        Log.d("zzl",keyword)
        val body:RequestBody =
            RequestBody.create("application/json;charset=UTF-8".toMediaTypeOrNull(),GSON.toJson(map))
        val books=ServiceCreator.apiService.searchBook(body)
        Log.d("zzl",books.toString())
        books
    }

//    @GET("book/chapter_list/100/{bookId}.txt")
//    suspend fun searchToc(@Path("bookId") bookId:String): ApiResult<List<TocResp>>
        suspend fun searchToc(bookId:String)= withContext(Dispatchers.IO){
        Log.d("zzl",bookId.toString())
         val tocs=ServiceCreator.apiService1.searchToc(bookId+".txt")
        tocs
}

}